package spark.network.strategy;

import org.apache.log4j.Logger;
import spark.network.ClockSynchronizer;
import spark.network.IConnections;
import spark.network.IPreLoginResponseResultListener;
import spark.network.NetworkConnection;
import spark.network.protocol.*;
import spark.utility.OutWrapper;

import java.util.Collection;

public class PreLoginResponseAckStrategy implements IProtocolHandleStrategy<PreLoginResponseAck> {
	private static Logger logger = Logger.getLogger(PreLoginResponseAckStrategy.class);
	private ClockSynchronizer clockSynchronizer;
	private int clockSyncRequestsToSend;

	public PreLoginResponseAckStrategy(ClockSynchronizer clockSynchronizer, int clockSyncRequestsToSend) {
		this.clockSynchronizer = clockSynchronizer;
		this.clockSyncRequestsToSend = clockSyncRequestsToSend;
	}

	@Override
	public void handle(PreLoginResponseAck packet, OutWrapper<Response> acknowledgement, Collection<Base> responses) {
		for(int i = 0; i < clockSyncRequestsToSend; i++) {
			ClockSyncReq clockSyncReq = new ClockSyncReq();
			clockSyncReq.setRequestNumber(clockSynchronizer.makeSyncData(packet.getSession()));
			responses.add(clockSyncReq);
		}
	}
}